//
//  USMD5.m
//  usale0001
//
//  Created by YU on 15/11/11.
//  Copyright © 2015年 YU. All rights reserved.
//

#import "USMD5.h"
#import <CommonCrypto/CommonDigest.h>
@implementation USMD5
+ (NSString *)MD5Encrypt:(NSString *)str
{
    const char *us_str = [str UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
//    extern unsigned char *CC_MD5(const void *data, CC_LONG len, unsigned char *md)
    //TODO: strlen return type is  size_t (uint64_t?)  add (CC_LONG) to convert  (yuguoping 2016.02.29)
    CC_MD5(us_str, (CC_LONG)strlen(us_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++){
        [hash appendFormat:@"%02X", result[i]];
    }
    return [hash lowercaseString];
}

@end
